/**
 *  @file SDLSplashSection.cpp
 *
 *  @date 21-nov-2009
 *  @author Ives van der Flaas
 */

#include <iostream>
#include <SDL.h>
#include "SDLSplashSection.h"
#include "SDLRectangleRepresentation.h"
#include "SDLWindow.h"
#include "SDLTimer.h"
#include "SDLFader.h"
#include "SDLColor.h"

namespace si_sdl
{

SDLSplashSection::SDLSplashSection(
		SDLApplication& parent,
		SDLWindow& win):
			SDLApplicationSection(parent, win),
			fRepresentation("images/splash.png"),
			fOpacity(1.0)


{

}

SDLSplashSection::~SDLSplashSection()
{
	// TODO Auto-generated destructor stub
}

void SDLSplashSection::newFrame(double timeSinceLastFrame)
{
	static SDLFader fader(Color(0,0,0), FADE_FROM_COLOR, 15);
	static SDLTimer timer;

	if(timer.poll() > 9.0) // after 7 seconds, goto intro
		fParent.changeSectionTo(si::INTRO);

	fRepresentation.draw(si::Vector2(-4.0,3.0), si::Vector2(8,6));
	fader.update(timeSinceLastFrame);
	fader.draw();





}

void SDLSplashSection::onSDLEvent(SDL_Event & event)
{
	SDLApplicationSection::onSDLEvent(event); // make sure SDL_QUIT's are caught...

	// When user presses space goto menu
	if(event.type == SDL_KEYDOWN)
		if(event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_ESCAPE)
			fParent.changeSectionTo(si::INTRO);
}

}
